package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbCapacityApproveDetailFile;
import com.sailfish.springbootdemo.pojo.db2.PcbNewTechnologyFile;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface PcbCapacityApproveDetailFileDao {
    @Results(id = "pcbCapacityApproveDetailFileResultMap", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER),
            @Result(column = "flow_type", property = "flowType", jdbcType = JdbcType.INTEGER),
            @Result(column = "data_id", property = "dataId", jdbcType = JdbcType.INTEGER),
            @Result(column = "detail_data_id", property = "detailDataId", jdbcType = JdbcType.INTEGER),
            @Result(column = "file_name", property = "fileName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "file_extend", property = "fileExtend", jdbcType = JdbcType.VARCHAR),
            @Result(column = "file_relate_path", property = "fileRelatePath", jdbcType = JdbcType.VARCHAR),
            @Result(column = "file_type", property = "fileType", jdbcType = JdbcType.VARCHAR),
            @Result(column = "url", property = "url", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "secret_key", property = "secretKey", jdbcType = JdbcType.VARCHAR),
            @Result(column = "file_sid", property = "fileSid", jdbcType = JdbcType.VARCHAR),
    })

    /*
     *查询单个
     */
    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.PCB_CAPAICTY_APPROVE_DETAIL_FILE +
            " where id = #{id}" +
            "</script>")
    PcbCapacityApproveDetailFile getById(@Param("id") Integer id);

    /*
     *按条件查询
     */
    @Select("<script> " +
            "select * " +
            "from " + DB2TableName.PCB_CAPAICTY_APPROVE_DETAIL_FILE +
            "<where>" +
            "<if test='flowType != null'>" +
            " and flow_type = #{flowType} " +
            "</if>" +
            "<if test='detailDataId != null'>" +
            " and detail_data_id = #{detailDataId} " +
            "</if>" +
            "</where>" +
            "</script>")
    @ResultMap(value = "pcbCapacityApproveDetailFileResultMap")
    List<PcbCapacityApproveDetailFile> getByLimit(@Param("flowType") Integer flowType, @Param("detailDataId") Integer detailDataId);

    /*
     *新增所有列
     */
    @Insert("insert into " + DB2TableName.PCB_CAPAICTY_APPROVE_DETAIL_FILE + " (flow_type, data_id, detail_data_id, file_name, file_extend, file_relate_path, file_type, url, remark, secret_key, file_sid, create_time, create_user, update_time, update_user, status, sort) values " +
            "(#{flowType}, #{dataId}, #{detailDataId}, #{fileName}, #{fileExtend}, #{fileRelatePath}, #{fileType}, #{url}, #{remark}, #{secretKey}, #{fileSid}, #{createTime}, #{createUser}, #{updateTime}, #{updateUser}, #{status}, #{sort})")
    // 显式设置主键
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer insert(PcbCapacityApproveDetailFile param);

    /*
     *删除
     */
    @Delete("<script>" +
            "delete from " + DB2TableName.PCB_CAPAICTY_APPROVE_DETAIL_FILE +
            "<where>" +
            "<if test='flowType != null'>" +
            " and flow_type = #{flowType} " +
            "</if>" +
            "<if test='detailDataId != null'>" +
            " and detail_data_id = #{detailDataId} " +
            "</if>" +
            "</where>" +
            "</script>")
    Integer delete(@Param("flowType") Integer flowType, @Param("detailDataId") Integer detailDataId);

}
